home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1993 / Internet Info CD-ROM (Walnut Creek) (1993).iso / networking / terms / tipx / acu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-11  |  4.4 KB  |  179 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)acu.c    5.6 (Berkeley) 9/2/88";
  20. #endif /* not lint */
  21.  
  22. #include "tip.h"
  23.  
  24. static acu_t *acu = NOACU;
  25. static int conflag;
  26. static sigfunc_t acuabort();
  27. static acu_t *acutype();
  28. static jmp_buf jmpbuf;
  29. /*
  30.  * Establish connection for tip
  31.  *
  32.  * If DU is true, we should dial an ACU whose type is AT.
  33.  * The phone numbers are in PN, and the call unit is in CU.
  34.  *
  35.  * If the PN is an '@', then we consult the PHONES file for
  36.  *   the phone numbers.  This file is /etc/phones, unless overriden
  37.  *   by an exported shell variable.
  38.  *
  39.  * The data base files must be in the format:
  40.  *    host-name[ \t]*phone-number
  41.  *   with the possibility of multiple phone numbers
  42.  *   for a single host acting as a rotary (in the order
  43.  *   found in the file).
  44.  */
  45. char *
  46. lconnect()
  47. {
  48.     register char *cp = PN;
  49.     char *phnum, string[256];
  50.     FILE *fd;
  51.     int tried = 0;
  52.  
  53.     if (!DU) {        /* regular connect message */
  54.         if (CM != NOSTR)
  55.             pwrite(FD, CM, size(CM));
  56.         logent(value(HOST), "", DV, "call completed");
  57.         return (NOSTR);
  58.     }
  59.     /*
  60.      * @ =>'s use data base in PHONES environment variable
  61.      *        otherwise, use /etc/phones
  62.      */
  63.     signal(SIGINT, acuabort);
  64.     signal(SIGQUIT, acuabort);
  65.     if (setjmp(jmpbuf)) {
  66.         signal(SIGINT, SIG_IGN);
  67.         signal(SIGQUIT, SIG_IGN);
  68.         printf("\ncall aborted\n");
  69.         logent(value(HOST), "", "", "call aborted");
  70.         if (slip)
  71.             abort_slip();
  72.         if (acu != NOACU) {
  73.             boolean(value(VERBOSE)) = FALSE;
  74.             if (conflag)
  75.                 disconnect(NOSTR);
  76.             else
  77.                 (*acu->acu_abort)();
  78.         }
  79.         return ("interrupt");
  80.     }
  81.     if ((acu = acutype(AT)) == NOACU)
  82.         return ("unknown ACU type");
  83.     if (*cp != '@') {
  84.         while (*cp) {
  85.             for (phnum = cp; *cp && *cp != ','; cp++)
  86.                 ;
  87.             if (*cp)
  88.                 *cp++ = '\0';
  89.             
  90.             if (conflag = (*acu->acu_dialer)(phnum, CU)) {
  91.                 logent(value(HOST), phnum, acu->acu_name,
  92.                     "call completed");
  93.                 return (NOSTR);
  94.             } else
  95.                 logent(value(HOST), phnum, acu->acu_name,
  96.                     "call failed");
  97.             tried++;
  98.         }
  99.     } else {
  100.         if ((fd = fopen(PH, "r")) == NOFILE) {
  101.             printf("%s: ", PH);
  102.             return ("can't open phone number file");
  103.         }
  104.         while (fgets(string, sizeof(string), fd) != NOSTR) {
  105.             for (cp = string; !any(*cp, " \t\n"); cp++)
  106.                 ;
  107.             if (*cp == '\n') {
  108.                 fclose(fd);
  109.                 return ("unrecognizable host name");
  110.             }
  111.             *cp++ = '\0';
  112.             if (strcmp(string, value(HOST)))
  113.                 continue;
  114.             while (any(*cp, " \t"))
  115.                 cp++;
  116.             if (*cp == '\n') {
  117.                 fclose(fd);
  118.                 return ("missing phone number");
  119.             }
  120.             for (phnum = cp; *cp && *cp != ',' && *cp != '\n'; cp++)
  121.                 ;
  122.             if (*cp)
  123.                 *cp++ = '\0';
  124.             
  125.             if (conflag = (*acu->acu_dialer)(phnum, CU)) {
  126.                 fclose(fd);
  127.                 logent(value(HOST), phnum, acu->acu_name,
  128.                     "call completed");
  129.                 return (NOSTR);
  130.             } else
  131.                 logent(value(HOST), phnum, acu->acu_name,
  132.                     "call failed");
  133.             tried++;
  134.         }
  135.         fclose(fd);
  136.     }
  137.     if (!tried)
  138.         logent(value(HOST), "", acu->acu_name, "missing phone number");
  139.     else
  140.         (*acu->acu_abort)();
  141.     return (tried ? "call failed" : "missing phone number");
  142. }
  143.  
  144. disconnect(reason)
  145.     char *reason;
  146. {
  147.     if (!conflag) {
  148.         logent(value(HOST), "", DV, "call terminated");
  149.         return;
  150.     }
  151.     if (reason == NOSTR) {
  152.         logent(value(HOST), "", acu->acu_name, "call terminated");
  153.         if (boolean(value(VERBOSE)))
  154.             printf("\r\ndisconnecting...");
  155.     } else 
  156.         logent(value(HOST), "", acu->acu_name, reason);
  157.     (*acu->acu_disconnect)();
  158. }
  159.  
  160. static sigfunc_t
  161. acuabort(s)
  162. {
  163.     signal(s, SIG_IGN);
  164.     longjmp(jmpbuf, 1);
  165. }
  166.  
  167. static acu_t *
  168. acutype(s)
  169.     register char *s;
  170. {
  171.     register acu_t *p;
  172.     extern acu_t acutable[];
  173.  
  174.     for (p = acutable; p->acu_name != '\0'; p++)
  175.         if (!strcmp(s, p->acu_name))
  176.             return (p);
  177.     return (NOACU);
  178. }
  179.